//
//  UIView+OAPositionExtension.m
//  OutsourceAXSDKDemo
//
//  Created by ChenJie on 2/27/20.
//  Copyright © 2020 Mist. All rights reserved.
//

#import "UIView+OAPositionExtension.h"

@implementation UIView (OAPositionExtension)

//
- (CGFloat)oa_left {
    return self.frame.origin.x;
}

- (void)oa_setLeft:(CGFloat)oa_left {
    CGRect frame = self.frame;
    frame.origin.x = oa_left;
    self.frame = frame;
}

//
- (CGFloat)oa_top {
    return self.frame.origin.y;
}

- (void)oa_setTop:(CGFloat)oa_top {
    CGRect frame = self.frame;
    frame.origin.y = oa_top;
    self.frame = frame;
}

//
- (CGFloat)oa_right {
    return CGRectGetMaxX(self.frame);
}

- (void)oa_setRight:(CGFloat)oa_right {
    if (!self.superview) {
        return;
    }
    
    self.oa_left = self.superview.oa_width - oa_right - self.oa_width;
}

//
- (CGFloat)oa_bottom {
    return CGRectGetMaxY(self.frame);
}

- (void)oa_setBottom:(CGFloat)oa_bottom {
    if (!self.superview) {
        return;
    }
    
    self.oa_top = self.superview.oa_height - oa_bottom - self.oa_height;
}

//
- (CGFloat)oa_width {
    return self.frame.size.width;
}

- (void)oa_setWidth:(CGFloat)oa_width {
    CGRect frame = self.frame;
    frame.size.width = oa_width;
    self.frame = frame;
}

//
- (CGFloat)oa_height {
    return self.frame.size.height;
}

- (void)oa_setHeight:(CGFloat)oa_height {
    CGRect frame = self.frame;
    frame.size.height = oa_height;
    self.frame = frame;
}

//
- (CGFloat)oa_centerLeft {
    return self.center.x;
}

- (void)oa_setCenterLeft:(CGFloat)oa_centerLeft {
    self.center = CGPointMake(oa_centerLeft, self.center.y);
}

//
- (CGFloat)oa_centerTop {
    return self.center.y;
}

- (void)oa_setCenterTop:(CGFloat)oa_centerTop {
    self.center = CGPointMake(self.center.x, oa_centerTop);
}

@end
